package net.wesley.android.city;

import android.os.Handler;
import android.os.Message;
import net.wesley.android.City;
import net.yebaihe.sdk.HttpConnection;

public class XiAn extends City {

	private Handler handler=new Handler(){
		public void handleMessage(Message message){
			switch (message.what){
			case HttpConnection.DID_ERROR://DID ERROR
				callback.onComplete(-1, "");
				break;
			case HttpConnection.DID_SUCCEED://DID SUCC
				String body=(String)message.obj;
				
				int index=body.indexOf("alert(\"");
				if (index>0){
					callback.onComplete(-10031, "ret:"+body.substring(index+7).split("\"")[0]);
					return;
				}
				
				int idx=body.indexOf("信息来源</b>");
				if (idx>0){
					String str=body.substring(idx).split("</table>")[0];
					String[] rows=str.split("<TR");
					int total=0;
					String ret="";
					for (int i=1;i<rows.length;i++){
						String[] cols = rows[i].split("<td ");
						String shijian=cols[3].split("</td")[0].split(">")[1];
						String didian=cols[4].split("</td")[0].split(">")[1];
						String code=cols[5].split("</td")[0].split(">")[1];
						total+=1;
						ret+=String.format("shijian:%s\ndidian:%s\ncode:%s\n\n",shijian,didian,code);
					}
					callback.onComplete(total, ret);
					return;
				}
				callback.onComplete(0, "");
				break;
			}
		}
	};

	public void requestParamsFinish(String[] values) {
		new HttpConnection(ctx,handler,"GBK").get("http://117.36.53.122:9082/wfcx/query.do?actiontype=vioSurveil&hpzl=02&hphm="+chepai.substring(1)+"&tj=CLSBDH&tj_val="+values[0]);
	}

	@Override
	public boolean match(String chepai) {
		return chepai.startsWith("陕A");
	}

	@Override
	public String[] paramDesc() {
		String[] s={"车架号"};
		return s;
	}

}
